/**
 * <p>
 * 表格配置
 *
 * @Author：Roy
 * @Description：设备管理
 * @Date：Create by 2023-11-30 18:51:39
 */
// 隐藏操作按钮的规则配置，字段名：isEdit
const isHidden = (list, row) => {
  const { isEdit } = row || {}
  return list.includes(String(isEdit))
}

const headerConfig = {
  'physicalModel': [
    {
      prop: 'id',
      name: '编号',
      minWidth: 110
    },
    {
      prop: 'createTm',
      name: '创建时间',
      minWidth: 110
    },
    {
      prop: 'modelName',
      name: '名称',
      minWidth: 110
    },
    {
      prop: 'modelTag',
      name: '标识符',
      minWidth: 150
    },
    {
      prop: 'measurementParameters',
      name: '计量参数',
      minWidth: 90,
      formatter(row, column, cell, index) {
        return row.modelFeatures.includes('4') ? '是' : '否'
      }
    },
    {
      prop: 'realTimeMonitor',
      name: '实时监测',
      minWidth: 90,
      formatter(row, column, cell, index) {
        return row.modelFeatures.includes('1') ? '是' : '否'
      }
    },
    {
      prop: 'readOnly',
      name: '只读',
      minWidth: 110,
      formatter(row, column, cell, index) {
        return row.modelFeatures.includes('2') ? '是' : '否'
      }
    },
    {
      prop: 'historyStorage',
      name: '历史存储',
      minWidth: 110,
      formatter(row, column, cell, index) {
        return row.modelFeatures.includes('3') ? '是' : '否'
      }
    },
    {
      prop: 'modelTypeName',
      name: '物模型类别',
      minWidth: 110
    },
    {
      prop: 'fieldTypeName',
      name: '数据类型',
      minWidth: 110
    },
    {
      prop: 'dataExt',
      name: '数据定义',
      minWidth: 220,
      formatter(row, column, cell, index) {
        const data = row.dataExtMap
        let html = '<div class="ext">'
        switch (row.fieldType) {
          case '1':
          case '2': // 小数
            if (data.dataType === '1') { // 动态数据
              html += '<div style="display: flex"><span style="width: 100px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">最大值：<span style="color: red">' + data.maxValue + '</span></span>' +
                '<span>最小值：<span style="color: red">' + data.minValue + '</span></span>' +
                '</div>'
                + '<div style="display: flex"><span style="width: 100px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">步长：<span style="color: red">' + data.step + '</span></span>' +
                '<span>单位：<span style="color: red">' + data.unit + '</span></span>' +
                '</div>'
            } else {
              html += '<div style="display: flex"><span style="width: 100px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">额定值：<span style="color: red">' + data.fixedValue + '</span></span>' +
                '<span>单位：<span style="color: red">' + data.unit + '</span></span>' +
                '</div>'
            }
            break
          case '3': // 小数
            html += '<div style="display: flex">' +
              '<span style="width: 100px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">0：<span style="color: red">' + data.falseValue + '</span></span>' +
              '<span>1：<span style="color: red">' + data.trueValue + '</span></span></div>'
            break
          case '4':
            for (let item of data.enumList) {
              html += '<div style="display: flex"><span style="width: 100px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">名称：<span style="color: red">' + item.label + '</span></span>' +
                '<span>值：<span style="color: red">' + item.value + '</span></span>' +
                '</div>'
            }
            break
          case '5':
            html += '<div>最大长度：<span style="color: red">' + data.maxLength + '</span></div>'
            break
          case '6':
            html += '<div>元素个数：<span style="color: red">' + data.arrayLength + '</span></div>'
            break
          case '7': // obj
            break
        }
        return html + '</div>'
      }
    },
    {
      name: '操作',
      width: 200,
      fixed: 'right',
      thStyle: { 'text-align': 'left' },
      operateList: [
        {
          type: 'btnText',
          label: '编辑',
          id: 'physicalmodel-edit',
          authId: 'ecp-admin:physicalmodel:update',
          config: { type: 'text' },
          style: { color: 'rgb(219,139,57)' },
          hidden: (val) => {
            return false // !isHidden(['1'], val)
          }
        },
        {
          type: 'btnText',
          label: '删除',
          id: 'physicalmodel-delete',
          authId: 'ecp-admin:physicalmodel:deleteById',
          isMore: true,
          config: { type: 'text' },
          style: { color: '#ff0000' },
          hidden: (val) => {
            return false // !isHidden(['1'], val)
          }
        }
      ]
    }
  ]
}

export default {}
export { headerConfig }
